package nio;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * Instruction：
 * Author：@author MaLi
 */
public class BioSocketClient {
    //创建客户端连接服务器, 发送一条数据, 并接收数据
    public void startClient() {
        Socket socket = new Socket();
        try {
            socket.connect(new InetSocketAddress(8888));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            writer.write("客户端消息: 客户端请求连接");
            writer.newLine();
            writer.flush();
            //等待接收服务端的响应
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String msg = reader.readLine();
            System.out.println("服务端消息: " + msg);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

    public static void main(String[] args) {
        BioSocketClient client = new BioSocketClient();
        client.startClient();
    }
}
